package com.example.task1.ui.AllService.bus;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.base.BaseActivity;
import com.example.task1.bean.BusOrderBean;
import com.example.task1.http.Api;
import com.example.task1.util.ApiResp;
import com.example.task1.util.CallBack;

import retrofit2.Call;

public class BusOrderActivity extends BaseActivity {

    private RecyclerView rvList;
    private BusOrderAdapter mBusOrderAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bus_order);
        initView();
        setAdapter();
        initData();
    }

    private void initData() {
        Call<ApiResp> apiRespCall = Api.api().get(MyApplication.TOKEN, "/prod-api/api/bus/order/list");
        Api.send(apiRespCall, BusOrderBean.class, new CallBack<BusOrderBean>() {
            @Override
            public void success(BusOrderBean data) {
                mBusOrderAdapter.setData(data.getRows());
            }

            @Override
            public void error(String msg) {

            }
        });
    }

    private void setAdapter() {
        mBusOrderAdapter = new BusOrderAdapter(this);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        rvList.setAdapter(mBusOrderAdapter);
        rvList.setLayoutManager(linearLayoutManager);
    }

    @Override
    public String getMyTitle() {
        return "我的订单";
    }

    private void initView() {
        rvList = findViewById(R.id.rv_list);
    }
}